package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.Volunteer;
import com.ruoyi.manage.service.IVolunteerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 志愿者管理Controller
 * 
 * @author Admin
 * @date 2025-09-06
 */
@RestController
@RequestMapping("/manage/volunteer")
public class VolunteerController extends BaseController
{
    @Autowired
    private IVolunteerService volunteerService;

    /**
     * 查询志愿者管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:volunteer:list')")
    @GetMapping("/list")
    public TableDataInfo list(Volunteer volunteer)
    {
        startPage();
        List<Volunteer> list = volunteerService.selectVolunteerList(volunteer);
        return getDataTable(list);
    }

    /**
     * 导出志愿者管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:volunteer:export')")
    @Log(title = "志愿者管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Volunteer volunteer)
    {
        List<Volunteer> list = volunteerService.selectVolunteerList(volunteer);
        ExcelUtil<Volunteer> util = new ExcelUtil<Volunteer>(Volunteer.class);
        util.exportExcel(response, list, "志愿者管理数据");
    }

    /**
     * 获取志愿者管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:volunteer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(volunteerService.selectVolunteerById(id));
    }

    /**
     * 新增志愿者管理
     */
    @PreAuthorize("@ss.hasPermi('manage:volunteer:add')")
    @Log(title = "志愿者管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Volunteer volunteer)
    {
        return toAjax(volunteerService.insertVolunteer(volunteer));
    }

    /**
     * 修改志愿者管理
     */
    @PreAuthorize("@ss.hasPermi('manage:volunteer:edit')")
    @Log(title = "志愿者管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Volunteer volunteer)
    {
        return toAjax(volunteerService.updateVolunteer(volunteer));
    }

    /**
     * 删除志愿者管理
     */
    @PreAuthorize("@ss.hasPermi('manage:volunteer:remove')")
    @Log(title = "志愿者管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(volunteerService.deleteVolunteerByIds(ids));
    }
}
